angular.module('mychat2').controller('MessageCreatorCtrl', ['$scope','server',function($scope, server) {
  $scope.createMessage = function () {
    if($scope.newMessage){
      server.createMessage({
        mcontent:$scope.newMessage,
        muser:$scope.me,
        roomId:$scope.room.roomId,
      });
      $scope.newMessage = ''
    }    
  }
}]);
angular.module('mychat2').controller('RoomCtrl', ['$scope','$routeParams','server',function($scope,$routeParams,server) {

  $scope.room = server.getRoom($routeParams._roomId);
  console.log($scope.room);
  server.joinRoom($routeParams._roomId);

  $scope.$on('$routeChangeStart', function() {
    server.leaveRoom({
      userId: $scope.me._id,
      roomId: $scope.room.roomId
    })
  })
}]);